%% this function resamples the data set from the original dataset (so uses the same 
% pairs of data) 
function [corr, low_ci, up_ci, corr_iter] = corr_bootstrap(x, y, N, ci_value)

ns = length(x);

corr = corrcoef(x,y);
corr = corr(2,1);

corr_iter = zeros(N,1);

for i=1:N
    sample_order = randi(ns,ns,1);
    
    new_x = x(sample_order);
    new_y = y(sample_order);
    
    r_aux = corrcoef(new_x, new_y);
    corr_iter(i) = r_aux(1,2);
end

low_ci = quantile(corr_iter, (1-ci_value)/2);
up_ci = quantile(corr_iter, ci_value + (1-ci_value)/2);